package com.example.learn.hwod;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Scanner;

public class _06boos的收入 {
    //分销商id-分销商收入
    static HashMap<String, Long> incomeMap = new HashMap<>();

    //所有分销商id
    static HashSet<String> agents = new HashSet<>();

    //分销商和上级分销商
    static HashMap<String, String> ch_fa = new HashMap<>();

    static HashMap<String, ArrayList<String>> fa_ch = new HashMap<String, ArrayList<String>>();
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        for (int i = 0; i < n; i++) {
            String ch_id = sc.next();
            String fa_id = sc.next();
            long income = sc.nextLong();

            incomeMap.put(ch_id, income);
            agents.add(ch_id);
            agents.add(fa_id);
            ch_fa.put(ch_id, fa_id);
            fa_ch.putIfAbsent(fa_id, new ArrayList<>());
            fa_ch.putIfAbsent(ch_id, new ArrayList<>());
            fa_ch.get(fa_id).add(ch_id);
        }
        System.out.println(bossIncome());


    }

    private static String bossIncome() {
        for (String agent : agents) {
            if (!ch_fa.containsKey(agent)) {
                incomeMap.put(agent,0L);
                dfs(agent);
                return agent+" "+incomeMap.get(agent);
            }
        }
        return "";
    }

    private static void dfs(String fa_id) {
        ArrayList<String> children = fa_ch.get(fa_id);
        if (!children.isEmpty()) {
            for (String child : children) {
                dfs(child);
                incomeMap.put(fa_id, incomeMap.get(fa_id)+incomeMap.get(child)/100*15);
            }
        }


    }
}
